package com.yzb.boot;

import com.yzb.MyRunBoot;
import com.yzb.config.WebServerFactory;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

public class MySpringApplication {

    public static void run() throws Exception {
        //1.初始化ioc，
        AnnotationConfigWebApplicationContext ac=new AnnotationConfigWebApplicationContext();
        ac.register(MyRunBoot.class);   //把运行主类注册进入ioc容器，这样就可以传递@ComponentScan中规定的扫描包路径
        ac.refresh();                          //刷新

        //2.将dispatcherServlet放入到ioc容器中
        //这里采用AppConfig配置类中进行@Bean操作

        //3.启动tomcat
        WebServerFactory factory = ac.getBean(WebServerFactory.class);
        factory.createServer();

        //4.将dispatcherServlet加载到tomcat上下文中去
        //这里使用MySpringServletContainerInitializer中onStartup方法进行操作，
        // 需要在resources目录中配置javax.servlet.ServletContainerInitializer实现类为MySpringServletContainerInitializer中onStartup
    }
}
